cc.Class({
    extends: cc.Component,
    properties: {
        scrollView: cc.ScrollView,
        prefabItem: cc.Prefab
    },
    onLoad: function () {
        this.allAdInfoList = tywx.AdManager.allAdInfoList, console.log("this.allAdInfoList : ", this.allAdInfoList),
            this.layoutContent = this.scrollView.content, this.layoutComp = this.layoutContent.getComponent(cc.Layout),
            this.scrollView.node.on("touchend", this._touchEnd.bind(this), this), this.scrollView.node.on("touch-up", this._touchUp.bind(this), this),
            this.scrollView.node.on("scroll-began", this._scrollBegan.bind(this), this), this.scrollView.node.on("scroll-ended", this._scrollEnd.bind(this), this),
            this.scrollView.enabled = !1, this.node.scale = 0;
    },
    start: function () {
        this.initView();
    },
    show: function () {
        this.scrollView.enabled || (this.scrollView.enabled = !0);
        for (var e = 0; e < this.layoutContent.children.length; e++) {
            var t = this.layoutContent.children[e];
            this.resetScale(t);
        }
        this.layoutContent.x = 0, this.layoutContent.y = this.node.height / 2, this._runStartAction();
    },
    disShow: function () {
        this._runEndAction();
    },
    _touchEnd: function () {
        console.log("touchEnd"), this.isAniming || this._isScroll || (this._runEndAction(),
            this._isScroll = !1);
    },
    _touchUp: function () {
        console.log("touchUp");
    },
    _scrollBegan: function () {
        console.log("scrollBegan"), this._isScroll = !0;
    },
    _scrollEnd: function () {
        console.log("scrollEnd"), this._isScroll = !1;
    },
    initView: function () {
        if (this.allAdInfoList) {
            var e = this.allAdInfoList || [];
            if (e && e.length > 0) {
                var t = parseInt(e.length / 5), n = 0, o = 0;
                this.layoutComp && (n = this.layoutComp.paddingTop + this.layoutComp.paddingBottom + this.layoutComp.spacingY * (t - 1),
                    o = this.layoutComp.paddingLeft + this.layoutComp.paddingRight + 4 * this.layoutComp.spacingX),
                    this.layoutContent.parent.width = o + 5 * this.prefabItem.data.width, this.layoutContent.height = n + t * this.prefabItem.data.height,
                    this.layoutContent.width = this.layoutContent.parent.width, console.log("this.layoutContent.height :", this.layoutContent.height);
                for (var i = 0; i < e.length; i++) {
                    var a = this._createItem(), r = e[i];
                    if (a) {
                        var s = a.getComponent("adCrossItem");
                        s.scheduleOnce(this.resetScale.bind(this, a), .1), s.setItemData(r);
                    }
                }
            }
        } else console.error("AdCrossList_popupScript error :", this.allAdInfoList);
    },
    resetScale: function (e) {
        cc.isValid(e) && (e.scale = Global.config.nodeAdCrossScale);
    },
    _createItem: function () {
        var e = cc.instantiate(this.prefabItem);
        return this.layoutContent.addChild(e), e;
    },
    _runStartAction: function () {
        if (!this.isAniming) {
            this.isAniming = !0, this.node.stopAllActions();
            this.node.opacity = 0, this.node.scale = 1.5;
            var e = cc.spawn(cc.fadeIn(.2), cc.scaleTo(.2, 1));
            this.node.runAction(cc.sequence(e, cc.callFunc(function () {
                this.isAniming = !1;
            }.bind(this))));
        }
    },
    _runEndAction: function () {
        if (!this.isAniming) {
            this.isAniming = !0, this.node.stopAllActions();
            this.node.opacity = 255, this.node.scale = 1;
            var e = cc.spawn(cc.fadeOut(.2), cc.scaleTo(.2, 1.5));
            this.node.runAction(cc.sequence(e, cc.callFunc(function () {
                this.isAniming = !1, this.OnPanelClose();
            }.bind(this))));
        }
    },
    OnPanelClose: function () {
        console.log("OnPanelClose"), this.node.scale = 0, tywx.NotificationCenter.trigger(tywx.EventType.MSG_SHOW_GAME_INTERACTION, !0);
    }
})